package com.wangfugui.mybatisplus.common;

import lombok.Data;
import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private int code;
    private String msg;
    private T data;

    public static <T> Result<T> ofSuccess(T data) {
        Result<T> result = new Result<>();
        result.setCode(0);
        result.setMsg("success");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> ofSuccess() {
        Result<T> result = new Result<>();
        result.setCode(0);
        result.setMsg("success");
        return result;
    }


    public static Result<ErrorMessage> ofFail(ErrorMessage errorMessage) {
        Result<ErrorMessage> authcResult = new Result<>();
        authcResult.code = errorMessage.getCode();
        authcResult.msg = errorMessage.getMessage();
        return authcResult;
    }

    public static <T> Result<T>  ofFail(String errorMessage) {
        Result<T> authcResult = new Result<T>();
        authcResult.code = 100;
        authcResult.msg = errorMessage;
        return authcResult;
    }
}